function $ (elementId){
	return document.getElementById(elementId)
}
function checkUser(){
	console.log('用户名')
	var user=$("user").value
	var userId=$("user_prompt")
	userId.innerHTML=""
	var reg=/^[a-zA-Z][a-zA-Z0-9]{3,15}$/
	if(reg.test(user)==false){
		userId.innerHTML="用户名不正确"
		return false;
	}
	return true;
}
function checkPwd(){
	console.log('密码')
	var pwd=$("pwd").value
	var pwdId=$("pwd_prompt")
	pwdId.innerHTML=""
	var reg=/^[a-zA-Z0-9]{4,10}$/
	if(reg.test(pwd)==false){
		pwdId.innerHTML="密码错误"
		return false;
	}
	return true;
}
function checkRepwd(){
	console.log('重复密码')
	var pwd=$("pwd").value
	var repwd=$("repwd").value
	var repwdId=$("repwd_prompt")
	repwdId.innerHTML=""
	if(repwd != pwd){
		repwdId.innerHTML="密码不一致"
		return false
	}
	return true;
}
function checkEmail(){
	console.log('邮箱')
	var email=$("email").value;
	var email_prompt=$("email_prompt");
	//邮箱地址必须包含'@'符号和’符号,且’符号必须在'@'符号后,邮箱地址以.com或.cn结束
	var reg=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
	email_prompt.innerHTML =""
	if(reg.test(email)==false){
		email_prompt.innerHTML="Email格式不正确";
		return false;
	}
	return true;
}
function checkMobile(){
	console.log('手机号')
	var mobile= $("mobile").value;
	var mobileId= $("mobile_prompt");
	//手机号码为11位数字,且以1开头
	var reg=/^1[0-9]{10}$/
	if(reg.test(mobile)==false){
		mobileId.innerHTML="手机号码不正确"
		return false;
	}
	mobileId.innerHTML=""
	return true;
}
function enroll_btn(){
	var user=$("user").value
	var pwd=$("pwd").value
	var yhm=$("getuser").value
	var userInfo={"userName":user,"password":pwd,"user_name":yhm}
	var agree_btn=document.getElementById("agree_btn")
	if(!agree_btn.checked){
		alert("你还未请同意协议")
	}else{
		if(checkUser() && checkPwd() && checkRepwd() && checkEmail() && checkMobile()){
			localStorage.setItem("userInfo",JSON.stringify(userInfo))
			alert("注册成功")
			location.href="login.html"
		}else{
			alert("还有错误")
		}
	}
}
function return_btn(){
	location.href="login.html"
}
